package com.zsy.controller;

import com.zsy.pojo.Emp;
import com.zsy.pojo.EmpQueryParam;
import com.zsy.pojo.PageResult;
import com.zsy.pojo.Result;
import com.zsy.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: zhengsuyang
 * @Desc:
 * @create: 2025-09-10 16:45
 **/
@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController {
    @Autowired
    private EmpService empService;

    /**
     * 分页 + 条件查询
     * @param empQueryParam
     * @return
     */
    @GetMapping
    public Result queryPageEmp(EmpQueryParam empQueryParam){
       PageResult<Emp> pageResult = empService.queryPageEmp(empQueryParam);
       return Result.success(pageResult);
    }

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryEmpById(@PathVariable String id){
      Emp emp = empService.queryEmpById(id);
      return Result.success(emp);
    }

    /**
     * 查询员工列表
     * @return
     */
    @GetMapping("/list")
    public Result queryEmpList(){
        List<Emp> emp = empService.queryEmpList();
        return Result.success(emp);
    }

    /**
     * 新增员工
     * @param emp
     * @return
     */
    @PostMapping
    public Result addEmp(@RequestBody Emp emp){
        empService.addEmp(emp);
        return Result.success();
    }

    /**
     * 批量删除员工
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delEmpByIds(@RequestParam("ids") List<Integer> ids){
        log.info("删除员工：id{}", ids);
         empService.delEmpByIds(ids);
         return Result.success();
    }

    /**
     * 修改员工
     * @param emp
     * @return
     */
    @PutMapping
    public Result updateEmp(@RequestBody Emp emp){
        empService.updateEmp(emp);
        return Result.success();
    }
}
